<!DOCTYPE html>

<html>
<head>
  <title>Practical Domain Driven Design</title>

  <meta charset='utf-8'>
  <script src='http://html5slides.googlecode.com/svn/trunk/slides.js'></script>
</head>

<style>
  .slides.template-saltfx > article:not(.nobackground):not(.biglogo)
  {
    background: url(images/salt-kevindooley-slim-with-logo.jpg) 0 600px no-repeat;

    background-size: 100%, 225px;

    background-color: #e5eae0;
  }

  .slides.template-saltfx article.biglogo
  {
    background: white url(images/saltfxlogo-big.png) 50% 50% no-repeat;

    background-size: 600px;
  }
</style>

<body style='display: none'>

<section class='slides layout-regular template-saltfx'>

<!-- SLIDE: Logo -->
<!--<article class='biglogo'>
</article>-->

<!-- SLIDE: Title -->
<article>
  <h1>
    Practical Domain Driven Design
  </h1>

  <p>
    <a href="mailto:greg.b.major@gmail.com?Subject=Practical%20DDD%20Presentation">Greg Major</a>
    <br>
    June 20, 2012
  </p>
</article>

<!-- SLIDE: Domain Driven Design Review -->
<article>
  <h3>Domain Driven Design...</h3>
  <ul>
    <li>Is a term coined by <a href="https://twitter.com/#!/ericevans0">Eric Evans</a> in "Domain-Driven Design: Tackling Complexity in Software"</li>
    <li>Is an approach to building complicated software by deeply coupling the business concepts with the model</li>
	<li>Is not a technology, product, or methodology</li>
	<li>Emphasizes ubiquitous language</li>
	<li>Is best suited for teams with OOP experience using an iterative development process and working with a non-trivial domain</li>
  </ul>
</article>

<!-- TOC: Values -->
<article>
  <h3>Getting Started</h3>
  <ul>
    <li class="green"><b>Values</b>
    <ul>
      <li>String, Int, Double, etc...</li>
    </ul>
	</li>
    <li>Value Objects</li>
    <li>Entities</li>
    <li>Repositories</li>
    <li>Factories</li>
    <li>Services</li>
    <li>Other Stuff</li>
  </ul>
</article>

<!-- CODE: Intro_01, Raw SomeClass -->
<article>
  <h3>
    Ya Gotta Start Somewhere
  </h3>
  <iframe src="http://pastebin.com/embed_iframe.php?i=dmgp1gNZ" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_02, SomeClass With External Validation -->
<article class="smaller">
  <h3>
    Hmmm... We'd Better Validate
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=9GLQr76P" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: Do You Smell That? -->
<article>
  <h3>Do You Smell That?</h3>
  <ul>
    <li><i>"Hey! I thought we were validating phone numbers!"</i></li>
    <li><i>"Hey! I just created this customer, but now I get an error when I try to edit it!"</i></li>
	<li><i>"Hey! How come I can put dashes in the customer phone number on this screen, but not on that one?!"</i></li>
  </ul>
  <br />
  <p>What other problems does this technique cause?</p>
</article>

<!-- CODE: Intro_03, New PhoneNumber Class -->
<article>
    <h3>Okay, So Let's DRY It Up!</h3>
    <iframe src="http://pastebin.com/embed_iframe.php?i=5dsNSs3f" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_04, PhoneNumber Prevents Invalid State -->
<article class="smaller">
  <h3>Prevent Invalid State</h3>
    <iframe src="http://pastebin.com/embed_iframe.php?i=Mzd2gTgg" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- TOC: Value Object -->
<article>
  <h3>Hey, We Just Built A Value Object!</h3>
  <ul>
    <li>Values</li>
    <li class="green"><b>Value Objects</b>
	<ul>
      <li>Objects without conceptual identity used to describe some characteristic of a thing</li>
    </ul>
	</li>
    <li>Entities</li>
    <li>Repositories</li>
    <li>Factories</li>
    <li>Services</li>
    <li>Other Stuff</li>
  </ul>
</article>

<!-- SLIDE: Value Object Review -->
<article>
  <h3>Value Objects...</h3>
  <ul>
    <li>Describe characteristics of things</li>
    <li>Do not have their own identity</li>
    <li>Are usually immutable (don't share e.g., flyweight if you need to make it mutable)</li>
    <li>Should always be in a valid state</li>
    <li>Promote ubiquitous language</li>
    <li>Can reference entities (more on those later) and other value objects</li>
    <li>Are frequently used as arguments</li>
  </ul>
</article>

<!-- TOC: Entities -->
<article>
  <h3>Enter The Entity</h3>
  <ul>
    <li>Values</li>
    <li>Value Objects
    <li class="green"><b>Entities</b>
      <ul>
        <li>Objects not fundamentally defined by their attributes, but rather by a thread of continuity and identity</li>
      </ul>
	</li>
    <li>Repositories</li>
    <li>Factories</li>
    <li>Services</li>
    <li>Other Stuff</li>
  </ul>
</article>

<!-- CODE: Intro_05, First Look At Customer -->
<article class="smaller">
  <h3>Let's Look At That Customer Class</h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=K1v4tzPT" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_06, Customer Gets Validation -->
<article class="smaller">
  <h3>Hmmm... Better Validate Here, Too</h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=dHXntJtW" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_07, Customer! Defined Yourself! -->
<article class="smaller">
  <h3>
    Customer! Defend Yourself!
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=ptiNWGj9" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_08, Every Customer Must Have A Phone Number! -->
<article class="smaller">
  <h3>
    Hey! Every Customer Must Have a Phone Number!
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=2RNwck2B" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_09, Customer! Change State! -->
<article class="smaller">
  <h3>
    Hey! I Need To Change A Customer's Phone Number!
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=VeUJDMQV" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- QUOTE: Eric Evans On The Entity's Responsibility -->
<article class="smaller">
  <q>
    When an object is distinguished by its identity, rather than its attributes, make this primary to its definition in
    the model. Keep the class definition simple and focused on life cycle continuity and identity.
  </q>

  <div class='author'>
    Eric Evans
  </div>
</article>

<!-- CODE: Intro_10, Customer! Show Me Your Id! -->
<article class="smaller">
  <h3>
    Hmmm... We'd Should Add An Id
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=t66HT9du" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: Warnings -->
<article>
  <h3>Warning...</h3>
  <ul>
    <li>Be mindful of the Anemic Domain Model Anti-Pattern</li>
	<li>Don't trust the language's identity system</li>
	<li>Favor natural domain keys (e.g., "Part Number", "Serial Number", "Model Line") over artibtrary values</li>
	<li>Do not change the id or goblins will eat you</li>
	<li>Do not confuse an entity id with a persistence id</li>
  </ul>
  </ul>
</article>

<!-- QUOTE: Martin Fowler On The Anemic Domain Model Anti-Pattern -->
<article class="smaller">
  <q>
    The fundamental horror of [the Anemic Domain Model Anti-Pattern] is that it's so contrary to the basic idea of object-oriented design; which is to combine data and process together.
  </q>

  <div class='author'>
    Eric Evans
  </div>
</article>

<!-- QUOTE: Swami Vivekananda On Extremism -->
<article class="smaller">
  <q>
    A good practice carried to an extreme and worked in accordance with the letter of the law becomes a positive evil.
  </q>

  <div class='author'>
    Swami Vivekananda
  </div>
</article>

<!-- SLIDE: Entity Review -->
<article>
  <h3>Entities...</h3>
  <ul>
    <li>Are defined by their identity</li>
    <li>Are note fundamentally defined by their attributes</li>
    <li>Are anything that has continuity through a life cycle</li>
    <li>Define an operation that is guaranteed to produce a unique result for each object</li>
    <li>Will have most of your domain's behaviors when well-written</li>
    <li>Should guard against becoming invalid</li>
    <li>Can change state, but never identity</li>
  </ul>
</article>

<!-- SLIDE: What About Lookups? -->
<article>
  <h3>What About Lookups?</h3>
  <ul>
    <li>What about them?</li>
    <ul>
      <li>Lookups aren't a DDD concern</li>
      <li>Lookups can be Values, Value Objects, Entities, or whatever</li>
    </ul>
	<li>For straight Value Object lookups, consider a property bag approach</li>
  </ul>
</article>

<!-- TOC: Repositories -->
<article>
  <h3>Excuse Me, I'm Looking For...</h3>
  <ul>
    <li>Values</li>
    <li>Value Objects</li>
    <li>Entities</li>
    <li class="green"><b>Repositories</b>
	  <ul>
        <li>Objects that provide a way to get a reference to an existing object</li>
      </ul>
	</li>
    <li>Factories</li>
    <li>Services</li>
    <li>Other Stuff</li>
  </ul>
</article>

<!-- CODE: Intro_11, A Repository Interface! -->
<article class="smaller">
  <h3>
    Do You Have Your Library Card?
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=1w4jgzvZ" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_12, Customer Repository Implementation -->
<article class="smaller">
  <h3>
    Build A Customer Repository
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=mfxkDWy2" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_13, Using The Customer Repository -->
<article class="smaller">
  <h3>
    Using The Customer Repository
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=9t10JcWp" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_14, Refining The Customer Repository -->
<article class="smaller">
  <h3>
    Refactoring The Customer Entity
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=K1rPY7uH" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: What Just Happened? -->
<article>
  <h3>What Just Happened?</h3>
  <ul>
    <li>We changed the empty private constructor to protected as required by our O/RM</li>
	<li>We changed private members to protected as required by our O/RM</li>
	<li>We marked some members as virtual as required by our O/RM</li>
	<li>We implemented a surrogate id for persistence reasons</li>
	<li>We implemented IEquatable and IComparable</li>
  </ul>
</article>

<!-- SLIDE: Repository Review -->
<article>
  <h3>Repositories...</h3>
  <ul>
    <li>Represent all objects of a certain type as a conceptual set</li>
	<li>Act as an in-memory collection</li>
	<li>Provide an intention-revealing interface</li>
	<li>Encapsulate complex persistence concerns</li>
	<li>Are not used by Entities or Value Objects</li>
  </ul>
</article>

<!-- TOC: Factories -->
<article>
  <h3>Finally! A Factory!</h3>
  <ul>
    <li>Values</li>
    <li>Value Objects</li>
    <li>Entities</li>
    <li>Repositories</li>
    <li class="green"><b>Factories</b>
	  <ul>
        <li>Objects that encapsulate the complexities of creating objects</li>
      </ul>
	</li>
    <li>Services</li>
    <li>Other Stuff</li>
  </ul>
</article>

<!-- CODE: Intro_15, Something Stinks About SomeClass -->
<article class="smaller">
  <h3>
    Something Stinks About SomeClass
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=vp4Pbnzf" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_16, Let's Build A Factory! -->
<article class="smaller">
  <h3>
    Let's Build A Factory!
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=xfMhnLJZ" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: Factory Review -->
<article>
  <h3>Factories...</h3>
  <ul>
    <li>Are responsible for creating complex objects and Aggregates</li>
	<li>Are frequently best expressed using a fluent, progressive interface</li>
	<li>Help you avoid making the client directly responsible for object creation</li>
	<li>Help to enforce encapsulation</li>
	<li>Can use Repositories (but watch your references)</li>
  </ul>
</article>

<!-- SLIDE: Shock And Horror! -->
<article class='fill'>
  <h3>
    Gasp! Can It Be?!? Oh...
  </h3>

  <p>
    <img src='images/the-horror.jpg'>
  </p>
</article>

<!-- TOC: Services -->
<article>
  <h3>We Specialize In Service!</h3>
  <ul>
    <li>Values</li>
    <li>Value Objects</li>
    <li>Entities</li>
    <li>Repositories</li>
    <li>Factories</li>
    <li class="green"><b>Services</b>
	  <ul>
        <li>Objects that do the things that Entities and Value Objects can't do for themselves</li>
      </ul>
	</li>
    <li>Other Stuff</li>
  </ul>
</article

<!-- SLIDE: Services Overview -->
<article>
  <h3>Services...</h3>
  <ul>
    <li>Do the things that Entities and Value Objects can't do for themselves</li>
	<li>Do not encapsulate state</li>
	<li>Should be used judiciously</li>
	<li>Should never strip Entities or Value Objects of their behavior</li>
	<li>Are frequently overloaded... be diligent!</li>
	<li>Can use Repositories (but watch your references)</li>
  </ul>
</article>

<!-- SLIDE: Wait A Minute... -->
<article>
  <h3>Wait A Minute...</h3>
  <ul>
    <li>Shouldn't phone numbers be unique?</li>
	<li>Does everybody in your house have the same phone number?</li>
	<li>How do we find all the customers with the same phone number?</li>
  </ul>
</article>

<!-- CODE: Intro_17, Approach 1: Extend The Repository -->
<article class="smaller">
  <h3>
    Extending The Repository
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=SxPL8vww" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: Dude! Where's My Method?!? -->
<article class='fill'>
  <p>
    <img src='images/lost-logo.jpg'>
  </p>
</article>

<!-- CODE: Intro_18, Approach 2: Create A Service -->
<article class="smaller">
  <h3>
    Alternate Approaches: Create a Service
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=SCpj2e1k" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- CODE: Intro_19, Approach 2: Implement The Specification Pattern -->
<article class="smaller">
  <h3>
    Alternate Approaches: Implement The Specification Pattern
  </h3>
<iframe src="http://pastebin.com/embed_iframe.php?i=V7fT67cR" style="border:none;width:100%;height:75%"></iframe>
</article>

<!-- SLIDE: What Haven't We Covered? -->
<article>
  <h3>So, What Haven't We Covered?</h3>
  <ul>
    <li>Modules</li>
    <li>Layers</li>
    <li>Aggregates</li>
    <li>Bounded Contexts</li>
    <li>Anti-Corruption Layers</li>
    <li>etc...</li>
  </ul>
</article>

<!-- SLIDE: Closer -->
<article>
  <h3>Thank You!</h3>
  <ul>
	<li>Frameworks</li>
    <ul>
      <li><a href='http://www.saltfx.net'>SaltFx</a></li>
	  <li><a href='http://sharparchitecture.net/'>S#arp Architecture</a></li>
	</ul>
	<li>Examples</li>
	<ul>
  	  <li><a href='http://microsoftnlayerapp.codeplex.com/'>Microsoft Spain's Domain Oriented N-Layered .NET 4.0 Sample App</a></li>
  	  <li><a href='http://code.google.com/p/ndddsample/'>ndddsample</a></li>
	  <li><a href='http://dddsamplenet.codeplex.com/'>DDDSample.Net</a></li>
	  <li><a href='http://codecampserver.codeplex.com/'>CodeCampserver</a></li>
	</ul>
  </ul>
</article>

</section>

</body>
</html>
